﻿@{
    ViewBag.Title = "Reporting Service";
}

@section featured {
    <section class="featured">
        <div class="content-wrapper" align="center">
            <hgroup class="title">
                <h1>@ViewBag.Message</h1>
            </hgroup>
        </div>
    </section>
}

@*@section scripts {
    <script type="text/javascript" src="~/Scripts/jquery-2.0.2.min.js"></script>
    <script type="text/javascript" src="~/Scripts/jqx-all.js"></script>
    <script type="text/javascript" src="~/Scripts/jqxdatetimeinput.js"></script>
    <script type="text/javascript" src="~/Scripts/jqxcalendar.js"></script>
    <script type="text/javascript" src="~/Scripts/jqxdata.js"></script>
    <script type="text/javascript" src="~/Scripts/jqxdata.export.js"></script>
    <script type="text/javascript" src="~/Scripts/jqxgrid.export.js"></script>
    <script type="text/javascript" src="~/Scripts/jqxbuttons.js"></script>
    <script type="text/javascript" src="~/Scripts/globalization/globalize.js"></script>
    <link rel="stylesheet" type="text/css" href="~/Scripts/styles/jqx.base.css" />
    <script type="text/javascript">
        $(document).ready(function () {
            var item = "";

            var source = [
                "--Please Select--",
                    "Invoice Report",
                    "Quotation Report",
                    "Work Order Report"
            ];
            // Create a jqxDropDownList
            $("#jqxdropdownlist").jqxDropDownList({ source: source, selectedIndex: 0, width: '200px', height: '25px', dropDownHorizontalAlignment: 'right' });
            //// disable the sixth item.
            //$("#jqxdropdownlist").jqxDropDownList('disableAt', 5);
            // bind to 'select' event.
            $('#jqxdropdownlist').bind('select', function (event) {
                var args = event.args;
                item = $('#jqxdropdownlist').jqxDropDownList('getItem', args.index);
                //alert('Selected: ' + item.label);

                if (item.label == "Invoice Report") {
                    source =
                    {
                        datatype: "json",
                        datafields: [
                             { name: 'InvoiceNo', type: 'string' },
                             { name: 'DebitNoteNo', type: 'string' },
                             { name: 'TotalAmount', type: 'decimal' },
                             { name: 'ReceiptNo', type: 'string' },
                             { name: 'ReceiptDate', type: 'datetime' }
                        ],
                        url: 'Report/GetInvoices'
                    };

                    var dataAdapter = new $.jqx.dataAdapter(source);
                    // initialize jqxGrid
                    $("#grid").jqxGrid(
                        {
                            width: 800,
                            source: dataAdapter,
                            altrows: true,
                            pageable: true,
                            columns: [
                                { text: "Invoice No", datafield: "InvoiceNo", width: '25%' },
                                { text: "DN No / Quo No", datafield: "DebitNoteNo", width: '20%' },
                                { text: "Total Amount", datafield: "TotalAmount", width: '15%', cellsformat: 'c2' },
                                { text: "Receipt No", datafield: "ReceiptNo", width: '20%' }
                                //{ text: "Receipt Date", datafield: "ReceiptDate", cellsformat: 'dd-MMM-yyyy', width: '17%' }
                            ]
                        });
                } else if (item.label == "Quotation Report") {
                    source =
                    {
                        datatype: "json",
                        datafields: [
                             { name: 'FMName', type: 'string' },
                             { name: 'QuotationCreationDate', type: 'date' },
                             { name: 'QuotationNo', type: 'string' },
                             { name: 'PONo', type: 'string' },
                             { name: 'TotalAmount', type: 'decimal', columntype: "numberinput" },
                             { name: 'SubContCode', type: 'string' },
                             { name: 'SubContAmount', type: 'decimal' },
                             { name: 'WorkCompletionDate', type: 'date' }
                        ],
                        url: 'Report/GetQuotations'
                    };

                    var dataAdapter = new $.jqx.dataAdapter(source);
                    // initialize jqxGrid
                    $("#grid").jqxGrid(
                        {
                            width: 950,
                            source: dataAdapter,
                            columnsheight: 50,
                            altrows: true,
                            pageable: true,
                            columns: [
                                { text: "FM", datafield: "FMName", width: '7%' },
                                { text: "Date", datafield: "QuotationCreationDate", cellsformat: 'dd-MMM-yyyy', width: '12%'},
                                { text: "Quotation No", datafield: "QuotationNo", width: '20%' },
                                { text: "PO No", datafield: "PONo", width: '15%' },
                                { text: "Total Amount", datafield: "TotalAmount", width: '15%', cellsformat: 'c2' },
                                { text: "Sub Contractor", datafield: "SubContCode", width: '20%' },
                                { text: "Sub Contractor Amount ", datafield: "SubContAmount", width: '17%', cellsformat: 'c2' },
                                { text: "Work Completion Date", datafield: "WorkCompletionDate", cellsformat: 'dd-MMM-yyyy', width: '17%' }
                            ]
                        });
                } else if (item.label == "Work Order Report") {
                    source =
                    {
                        datatype: "json",
                        datafields: [
                             { name: 'FMName', type: 'string' },
                             { name: 'ServiceOrderNo', type: 'string' },
                             { name: 'Location', type: 'string' },
                             { name: 'Description', type: 'string' },
                             { name: 'WorkOrderNo', type: 'string' },
                             { name: 'QuotationNo', type: 'string' }
                        ],
                        url: 'Report/GetOrders'
                    };

                    var dataAdapter = new $.jqx.dataAdapter(source);
                    // initialize jqxGrid
                    $("#grid").jqxGrid(
                        {
                            width: 900,
                            source: dataAdapter,
                            altrows: true,
                            pageable: true,
                            columns: [
                                { text: "FM", datafield: "FMName", width: '7%' },
                                { text: "Service Order No", datafield: "ServiceOrderNo", width: '20%' },
                                { text: "Location", datafield: "Location", width: '20%' },
                                { text: "Description", datafield: "Description", width: '20%' },
                                { text: "Work Order No", datafield: "WorkOrderNo", width: '20%' },
                                { text: "Quotation No", datafield: "QuotationNo", width: '20%' }
                            ]
                        });
                }
            });

            $("#excelExport").jqxButton({ theme: 'energyblue' });

            $("#excelExport").click(function () {
                var today = new Date();
                var year = today.getFullYear();
                var month = today.getMonth() + 1;
                var day = today.getDate();
                if (day < 10) { day = '0' + day }
                if (month < 10) { month = '0' + month }
                item.label = item.label + "_" + year.toString() + month.toString() + day.toString();

                $("#grid").jqxGrid('exportdata', 'xls', item.label);
            });
        });
    </script>
}*@

<section>
    @using (Html.BeginForm("ReportExtraction", "Report"))
    {
        <br align="center" />
        <input type="submit" value="Export to Excel" />
    }
</section>

<section>
    @using (Html.BeginForm("BackToMainMeun", "Home"))
    {
        <br align="center" />
        <input type="submit" value="Back To Main Menu" />
    }
</section>


